##########################################################################
## Replication code for                                                 ##
## War on Aisle 5: Casualties, National Identity, and Consumer Behavior ##
## Benjamin Helms, Sonal S. Pandya, and Rajkumar Venkatesan             ##
## January 19, 2024                                                     ##
## Journal of Conflict Resolution                                       ##
##########################################################################

## This file contains code to replicate all empirical analyses in the
## main text and Supplemental Information.

## Operating system: MacOS Sonoma version 14.0.
## Statistical software: R version 4.3.2

## Enter the working directory containing the analysis datasets here:
setwd("")

## Load necessary packages for cleaning and analysis.
library(sqldf)
library(data.table)
library(stringr)
library(haven)
library(lubridate)
library(lfe)
library(tidyverse)

## The code that follows assumes that the user has created a set
## of annual versions of the data for years 2003-2006, with the
## names data_03, data_04, data_05, and data_06. Additionally,
## the creation of these annual versions of the data rely on a
## similar version of the data constructed for 2002.

## The construction of the annual versions of the data uses
## supermarket scanner data that are subject to a data use
## agreement. Please see the Readme for additional information.

################################################################
## Table 2: Weekly Casualties and American Brand Share - 2003 ##
################################################################

## Model (1)
table2_model1 <- lm(dmshare ~ 
                      casul_ind*am4 + 
                      zhi*am4 + 
                      enlist*am4 + 
                      pop + 
                      dprice + 
                      dnsku,
                    data=data_03)

## Model (2)
table2_model2 <- lm(dmshare ~ 
                      casul_ind*am4 + 
                      iraq_nat_cas*am4 + 
                      zhi*am4 + 
                      enlist*am4 + 
                      pop + 
                      dprice + 
                      dnsku,
                    data=data_03)


#####################################################################
## Figure 3: Marginal Effect of Local Casualty on Change in Market ##
## Share Across Range of American Score, 2003                      ##
#####################################################################

beta1 <- coef(table2_model2)[2]
beta3 <- coef(table2_model2)[10]

V1 <- vcov(table2_model2)[2,2]
V3 <- vcov(table2_model2)[10,10]
Cov13 <- vcov(table2_model2)[10,2]

american_score <- 0:7

marg.effect <- beta1 + beta3*american_score

marg.effect.var <- V1 + american_score^2*V3 + 2*american_score*Cov13

marg.effect.se <- sqrt(marg.effect.var)

marg.effect.lb <- marg.effect - 1.96*marg.effect.se

marg.effect.ub <- marg.effect + 1.96*marg.effect.se

me.data <- data.frame(american_score,
                      marg.effect,
                      marg.effect.var,
                      marg.effect.se,
                      marg.effect.lb,
                      marg.effect.ub)

figure_3 <- ggplot(me.data, aes(x=american_score, y=marg.effect)) + 
  geom_line(size=0.75) + 
  geom_hline(yintercept=0, lty=2) + 
  geom_ribbon(aes(ymin=marg.effect.lb, ymax=marg.effect.ub), alpha = 0.25) +
  xlab(expression(AmericanScore[i])) + 
  scale_x_continuous(breaks=seq(0,7, by=1)) + 
  ylab(Marginal ~ Effect ~ of ~ LocalCasualty[jt]) + 
  theme_classic()

rm(beta1,
   beta3,
   V1,
   V3,
   Cov13,
   american_score,
   marg.effect,
   marg.effect.var,
   marg.effect.se,
   marg.effect.lb,
   marg.effect.ub,
   me.data)


####################################################################
## Table 3: Cumulative Casualties and American Brand Share - 2006 ##
####################################################################

## Model (1)
table3_model1 <- lm(dmshare ~ 
                      log_cum_iraq_cas*am4 + 
                      zhi*am4 + 
                      enlist*am4 + 
                      pop + 
                      dprice + 
                      dnsku, 
                    data=data_06)

## Model (2)
table3_model2 <- lm(dmshare ~ 
                      log_cum_iraq_cas*am4 + 
                      log_cum_iraq_nat_cas*am4 +
                      zhi*am4 + 
                      enlist*am4 + 
                      pop + 
                      dprice + 
                      dnsku, 
                    data=data_06)


############################################################################
## Figure 4: Marginal Effect of Cumulative Casualties on Change in Market ##
## Share Across Range of American Score, 2003                             ##
############################################################################

beta1 <- coef(table3_model2)[2]
beta3 <- coef(table3_model2)[10]

V1 <- vcov(table3_model2)[2,2]
V3 <- vcov(table3_model2)[10,10]
Cov13 <- vcov(table3_model2)[10,2]

american_score <- 0:7

marg.effect <- beta1 + beta3*american_score

marg.effect.var <- V1 + american_score^2*V3 + 2*american_score*Cov13

marg.effect.se <- sqrt(marg.effect.var)

marg.effect.lb <- marg.effect - 1.96*marg.effect.se

marg.effect.ub <- marg.effect + 1.96*marg.effect.se

me.data <- data.frame(american_score,
                      marg.effect,
                      marg.effect.var,
                      marg.effect.se,
                      marg.effect.lb,
                      marg.effect.ub)

figure_4 <- ggplot(me.data, aes(x=american_score, y=marg.effect)) + 
  geom_line(size=0.75) + 
  geom_hline(yintercept=0, lty=2) + 
  geom_ribbon(aes(ymin=marg.effect.lb, ymax=marg.effect.ub), alpha = 0.25) +
  xlab(expression(AmericanScore[i])) + 
  scale_x_continuous(breaks=seq(0,7, by=1)) + 
  ylab(Marginal ~ Effect ~ of ~ ln(CumulCasualties[jt])) + 
  theme_classic()

rm(beta1,
   beta3,
   V1,
   V3,
   Cov13,
   american_score,
   marg.effect,
   marg.effect.var,
   marg.effect.se,
   marg.effect.lb,
   marg.effect.ub,
   me.data)


#####################################################################
## Table 4: Cumulative Casualties and Demographic Variation - 2006 ##
#####################################################################

## Note: this model uses demographic data that is subject to a data
## use agreement. Please see the Readme for additional information.

## Model (1)
table4_model1 <- lm(dmshare ~
                      log_cum_iraq_cas*am4*bush + 
                      log_cum_iraq_cas*am4*whitecollar_percent + 
                      log_cum_iraq_cas*am4*armedforces_percent + 
                      log_cum_iraq_cas*am4*native_percent + 
                      log_cum_iraq_cas*am4*black_percent + 
                      log_cum_iraq_nat_cas*am4*bush +
                      log_cum_iraq_nat_cas*am4*whitecollar_percent +
                      log_cum_iraq_nat_cas*am4*armedforces_percent + 
                      log_cum_iraq_nat_cas*am4*native_percent +
                      log_cum_iraq_nat_cas*am4*black_percent +
                      zhi*am4 + 
                      enlist*am4 +
                      pop + 
                      dprice + 
                      dnsku,
                    data=filter(data_demo,
                                pop < (mean(pop) + 2*sd(pop)) & pop > (mean(pop) - 2*sd(pop))))


###############################################################################
## Appendix Table A.1: Weekly Casualties and American Brand Share, 2003-2006 ##
###############################################################################

## Model (1)
tableA1_model1 <- lm(dmshare ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_03)

## Model (2)
tableA1_model2 <- lm(dmshare ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_04)

## Model (3)
tableA1_model3 <- lm(dmshare ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_05)

## Model (4)
tableA1_model4 <- lm(dmshare ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_06)


##########################################################################
## Appendix Figure A.1: Marginal Effect of Local Casualty on Change in  ##
## Market Share Across Range of American Score, 2003-2006               ##
##########################################################################

## 2003

beta1 <- coef(tableA1_model1)[2]
beta3 <- coef(tableA1_model1)[10]

V1 <- vcov(tableA1_model1)[2,2]
V3 <- vcov(tableA1_model1)[10,10]
Cov13 <- vcov(tableA1_model1)[10,2]

american_score <- 0:7

marg.effect <- beta1 + beta3*american_score

marg.effect.var <- V1 + american_score^2*V3 + 2*american_score*Cov13

marg.effect.se <- sqrt(marg.effect.var)

marg.effect.lb <- marg.effect - 1.96*marg.effect.se

marg.effect.ub <- marg.effect + 1.96*marg.effect.se

me.data <- data.frame(american_score,
                      marg.effect,
                      marg.effect.var,
                      marg.effect.se,
                      marg.effect.lb,
                      marg.effect.ub)

figure_A1_2003 <- ggplot(me.data, aes(x=american_score, y=marg.effect)) + 
  geom_line(size=0.75) + 
  geom_hline(yintercept=0, lty=2) + 
  geom_ribbon(aes(ymin=marg.effect.lb, ymax=marg.effect.ub), alpha = 0.25) +
  xlab(expression(AmericanScore[i])) + 
  scale_x_continuous(breaks=seq(0,7, by=1)) + 
  ylab(Marginal ~ Effect ~ of ~ LocalCasualty[jt]) + 
  ggtitle("2003") + 
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5))

rm(beta1,
   beta3,
   V1,
   V3,
   Cov13,
   american_score,
   marg.effect,
   marg.effect.var,
   marg.effect.se,
   marg.effect.lb,
   marg.effect.ub,
   me.data)

## 2004

beta1 <- coef(tableA1_model2)[2]
beta3 <- coef(tableA1_model2)[10]

V1 <- vcov(tableA1_model2)[2,2]
V3 <- vcov(tableA1_model2)[10,10]
Cov13 <- vcov(tableA1_model2)[10,2]

american_score <- 0:7

marg.effect <- beta1 + beta3*american_score

marg.effect.var <- V1 + american_score^2*V3 + 2*american_score*Cov13

marg.effect.se <- sqrt(marg.effect.var)

marg.effect.lb <- marg.effect - 1.96*marg.effect.se

marg.effect.ub <- marg.effect + 1.96*marg.effect.se

me.data <- data.frame(american_score,
                      marg.effect,
                      marg.effect.var,
                      marg.effect.se,
                      marg.effect.lb,
                      marg.effect.ub)

figure_A1_2004 <- ggplot(me.data, aes(x=american_score, y=marg.effect)) + 
  geom_line(size=0.75) + 
  geom_hline(yintercept=0, lty=2) + 
  geom_ribbon(aes(ymin=marg.effect.lb, ymax=marg.effect.ub), alpha = 0.25) +
  xlab(expression(AmericanScore[i])) + 
  scale_x_continuous(breaks=seq(0,7, by=1)) + 
  ylab(Marginal ~ Effect ~ of ~ LocalCasualty[jt]) + 
  ggtitle("2004") + 
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5))

rm(beta1,
   beta3,
   V1,
   V3,
   Cov13,
   american_score,
   marg.effect,
   marg.effect.var,
   marg.effect.se,
   marg.effect.lb,
   marg.effect.ub,
   me.data)

## 2005

beta1 <- coef(tableA1_model3)[2]
beta3 <- coef(tableA1_model3)[10]

V1 <- vcov(tableA1_model3)[2,2]
V3 <- vcov(tableA1_model3)[10,10]
Cov13 <- vcov(tableA1_model3)[10,2]

american_score <- 0:7

marg.effect <- beta1 + beta3*american_score

marg.effect.var <- V1 + american_score^2*V3 + 2*american_score*Cov13

marg.effect.se <- sqrt(marg.effect.var)

marg.effect.lb <- marg.effect - 1.96*marg.effect.se

marg.effect.ub <- marg.effect + 1.96*marg.effect.se

me.data <- data.frame(american_score,
                      marg.effect,
                      marg.effect.var,
                      marg.effect.se,
                      marg.effect.lb,
                      marg.effect.ub)

figure_A1_2005 <- ggplot(me.data, aes(x=american_score, y=marg.effect)) + 
  geom_line(size=0.75) + 
  geom_hline(yintercept=0, lty=2) + 
  geom_ribbon(aes(ymin=marg.effect.lb, ymax=marg.effect.ub), alpha = 0.25) +
  xlab(expression(AmericanScore[i])) + 
  scale_x_continuous(breaks=seq(0,7, by=1)) + 
  ylab(Marginal ~ Effect ~ of ~ LocalCasualty[jt]) + 
  ggtitle("2005") + 
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5))

rm(beta1,
   beta3,
   V1,
   V3,
   Cov13,
   american_score,
   marg.effect,
   marg.effect.var,
   marg.effect.se,
   marg.effect.lb,
   marg.effect.ub,
   me.data)

## 2006

beta1 <- coef(tableA1_model4)[2]
beta3 <- coef(tableA1_model4)[10]

V1 <- vcov(tableA1_model4)[2,2]
V3 <- vcov(tableA1_model4)[10,10]
Cov13 <- vcov(tableA1_model4)[10,2]

american_score <- 0:7

marg.effect <- beta1 + beta3*american_score

marg.effect.var <- V1 + american_score^2*V3 + 2*american_score*Cov13

marg.effect.se <- sqrt(marg.effect.var)

marg.effect.lb <- marg.effect - 1.96*marg.effect.se

marg.effect.ub <- marg.effect + 1.96*marg.effect.se

me.data <- data.frame(american_score,
                      marg.effect,
                      marg.effect.var,
                      marg.effect.se,
                      marg.effect.lb,
                      marg.effect.ub)

figure_A1_2006 <- ggplot(me.data, aes(x=american_score, y=marg.effect)) + 
  geom_line(size=0.75) + 
  geom_hline(yintercept=0, lty=2) + 
  geom_ribbon(aes(ymin=marg.effect.lb, ymax=marg.effect.ub), alpha = 0.25) +
  xlab(expression(AmericanScore[i])) + 
  scale_x_continuous(breaks=seq(0,7, by=1)) + 
  ylab(Marginal ~ Effect ~ of ~ LocalCasualty[jt]) + 
  ggtitle("2006") + 
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5))

rm(beta1,
   beta3,
   V1,
   V3,
   Cov13,
   american_score,
   marg.effect,
   marg.effect.var,
   marg.effect.se,
   marg.effect.lb,
   marg.effect.ub,
   me.data)


######################################################################################
## Appendix Table A.2: Lagged Weekly Casualties and American Brand Share, 2003-2006 ##
######################################################################################

## Model (1)
tableA2_model1 <- lm(dmshare ~ 
                       lag_casul_ind*am4 + 
                       lag_iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku, 
                     data=data_03)

## Model (2)
tableA2_model2 <- lm(dmshare ~ 
                       lag_casul_ind*am4 + 
                       lag_iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku, 
                     data=data_04)

## Model (3)
tableA2_model3 <- lm(dmshare ~ 
                       lag_casul_ind*am4 + 
                       lag_iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku, 
                     data=data_05)

## Model (4)
tableA2_model4 <- lm(dmshare ~ 
                       lag_casul_ind*am4 + 
                       lag_iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku, 
                     data=data_06)


##################################################################################
## Appendix Table A.3: Weekly Casualties and American Brand Share, 2003-2006 -  ##
## County Fixed Effects                                                         ##
##################################################################################

## Model (1)
tableA3_model1 <- felm(dmshare ~ 
                         casul_ind*am4 + 
                         iraq_nat_cas*am4 + 
                         zhi*am4 + 
                         enlist*am4 + 
                         dprice + 
                         dnsku | 
                         fips | 
                         0 | 
                         0,
                       data=data_03)

## Model (2)
tableA3_model2 <- felm(dmshare ~ 
                         casul_ind*am4 + 
                         iraq_nat_cas*am4 + 
                         zhi*am4 + 
                         enlist*am4 + 
                         dprice + 
                         dnsku | 
                         fips | 
                         0 | 
                         0,
                       data=data_04)

## Model (3)
tableA3_model3 <- felm(dmshare ~ 
                         casul_ind*am4 + 
                         iraq_nat_cas*am4 + 
                         zhi*am4 + 
                         enlist*am4 + 
                         dprice + 
                         dnsku | 
                         fips | 
                         0 | 
                         0,
                       data=data_05)

## Model (4)
tableA3_model4 <- felm(dmshare ~ 
                         casul_ind*am4 + 
                         iraq_nat_cas*am4 + 
                         zhi*am4 + 
                         enlist*am4 + 
                         dprice + 
                         dnsku | 
                         fips | 
                         0 | 
                         0,
                       data=data_06)


##################################################################################
## Appendix Table A.4: Weekly Casualties and American Brand Share, 2003-2006 -  ##
## Controlling for Bush Vote Share                                              ##
##################################################################################

## Model (1)
tableA4_model1 <- lm(dmshare ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       bush*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku, 
                     data=data_03)

## Model (2)
tableA4_model2 <- lm(dmshare ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       bush*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku, 
                     data=data_04)

## Model (3)
tableA4_model3 <- lm(dmshare ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       bush*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku, 
                     data=data_05)

## Model (4)
tableA4_model4 <- lm(dmshare ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       bush*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku, 
                     data=data_06)


#################################################################################
## Appendix Table A.5: Weekly Casualties and American Brand Share, 2003-2006 - ##
## Including Afghanistan Casualties                                            ##
#################################################################################

## Model (1)
tableA5_model1 <- lm(dmshare ~ 
                       total_cas*am4 + 
                       total_nat_cas*am4 +
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_03)

## Model (2)
tableA5_model2 <- lm(dmshare ~ 
                       total_cas*am4 + 
                       total_nat_cas*am4 +
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_04)

## Model (3)
tableA5_model3 <- lm(dmshare ~ 
                       total_cas*am4 + 
                       total_nat_cas*am4 +
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_05)

## Model (4)
tableA5_model4 <- lm(dmshare ~ 
                       total_cas*am4 + 
                       total_nat_cas*am4 +
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_06)


#################################################################################
## Appendix Table A.6: Weekly Casualties and American Brand Share, 2003-2006 - ##  
## Store-Clustered Standard Errors                                             ##
#################################################################################

## Model (1)
tableA6_model1 <- felm(dmshare ~ 
                         casul_ind*am4 + 
                         iraq_nat_cas*am4 + 
                         zhi*am4 + 
                         enlist*am4 + 
                         pop + 
                         dprice + 
                         dnsku | 
                         0 | 
                         0 | 
                         store,
                       data=data_03)

## Model (2)
tableA6_model2 <- felm(dmshare ~ 
                         casul_ind*am4 + 
                         iraq_nat_cas*am4 + 
                         zhi*am4 + 
                         enlist*am4 + 
                         pop + 
                         dprice + 
                         dnsku | 
                         0 | 
                         0 | 
                         store,
                       data=data_04)

## Model (3)
tableA6_model3 <- felm(dmshare ~ 
                         casul_ind*am4 + 
                         iraq_nat_cas*am4 + 
                         zhi*am4 + 
                         enlist*am4 + 
                         pop + 
                         dprice + 
                         dnsku | 
                         0 | 
                         0 | 
                         store,
                       data=data_05)

## Model (4)
tableA6_model4 <- felm(dmshare ~ 
                         casul_ind*am4 + 
                         iraq_nat_cas*am4 + 
                         zhi*am4 + 
                         enlist*am4 + 
                         pop + 
                         dprice + 
                         dnsku | 
                         0 | 
                         0 | 
                         store,
                       data=data_06)


#################################################################################
## Appendix Table A.7: Weekly Casualties and American Brand Share, 2003-2006 - ##
## DMA-Level Indicator                                                         ##
#################################################################################

## Model (1)
tableA7_model1 <- lm(dmshare ~ 
                       dma_casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_03)

## Model (2)
tableA7_model2 <- lm(dmshare ~ 
                       dma_casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_04)

## Model (3)
tableA7_model3 <- lm(dmshare ~ 
                       dma_casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_05)

## Model (4)
tableA7_model4 <- lm(dmshare ~ 
                       dma_casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_06)


#################################################################################
## Appendix Table A.8: Weekly Casualties and American Brand Share, 2003-2006 - ##
## No. of DMA Casualties                                                       ##
#################################################################################

## Model (1)
tableA8_model1 <- lm(dmshare ~ 
                       dma_casualties*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_03)

## Model (2)
tableA8_model2 <- lm(dmshare ~ 
                       dma_casualties*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_04)

## Model (3)
tableA8_model3 <- lm(dmshare ~ 
                       dma_casualties*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_05)

## Model (4)
tableA8_model4 <- lm(dmshare ~ 
                       dma_casualties*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice + 
                       dnsku,
                     data=data_06)


#############################################################################################################
## Appendix Table A.9: Weekly Casualties and American Brand Share, 2003-2006 - Using 2002 as Baseline Year ##
#############################################################################################################

## Model (1)
tableA9_model1 <- lm(dmshare_2002 ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice_2002 + 
                       dnsku_2002,
                     data=data_03)

## Model (2)
tableA9_model2 <- lm(dmshare_2002 ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice_2002 + 
                       dnsku_2002,
                     data=data_04)

## Model (3)
tableA9_model3 <- lm(dmshare_2002 ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice_2002 + 
                       dnsku_2002,
                     data=data_05)

## Model (4)
tableA9_model4 <- lm(dmshare_2002 ~ 
                       casul_ind*am4 + 
                       iraq_nat_cas*am4 + 
                       zhi*am4 + 
                       enlist*am4 + 
                       pop + 
                       dprice_2002 + 
                       dnsku_2002,
                     data=data_06)


####################################################################################
## Appendix Table A.10: Cumulative Casualties and American Brand Share, 2003-2006 ##
####################################################################################

## Model (1)
tableA10_model1 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03)

## Model (2)
tableA10_model2 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04)

## Model (3)
tableA10_model3 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05)

## Model (4)
tableA10_model4 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06)


################################################################################
## Appendix Figure A.2: Marginal Effect of Cumulative Casualties on Change in ##
## Market Share Across Range of American Score, 2003                          ##
################################################################################

## 2003

beta1 <- coef(tableA10_model1)[2]
beta3 <- coef(tableA10_model1)[10]

V1 <- vcov(tableA10_model1)[2,2]
V3 <- vcov(tableA10_model1)[10,10]
Cov13 <- vcov(tableA10_model1)[10,2]

american_score <- 0:7

marg.effect <- beta1 + beta3*american_score

marg.effect.var <- V1 + american_score^2*V3 + 2*american_score*Cov13

marg.effect.se <- sqrt(marg.effect.var)

marg.effect.lb <- marg.effect - 1.96*marg.effect.se

marg.effect.ub <- marg.effect + 1.96*marg.effect.se

me.data <- data.frame(american_score,
                      marg.effect,
                      marg.effect.var,
                      marg.effect.se,
                      marg.effect.lb,
                      marg.effect.ub)

figure_A2_2003 <- ggplot(me.data, aes(x=american_score, y=marg.effect)) + 
  geom_line(size=0.75) + 
  geom_hline(yintercept=0, lty=2) + 
  geom_ribbon(aes(ymin=marg.effect.lb, ymax=marg.effect.ub), alpha = 0.25) +
  xlab(expression(AmericanScore[i])) + 
  scale_x_continuous(breaks=seq(0,7, by=1)) + 
  ylab(Marginal ~ Effect ~ of ~ ln(CumulCasualties[jt])) + 
  ggtitle("2003") + 
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5))

rm(beta1,
   beta3,
   V1,
   V3,
   Cov13,
   american_score,
   marg.effect,
   marg.effect.var,
   marg.effect.se,
   marg.effect.lb,
   marg.effect.ub,
   me.data)

## 2004

beta1 <- coef(tableA10_model2)[2]
beta3 <- coef(tableA10_model2)[10]

V1 <- vcov(tableA10_model2)[2,2]
V3 <- vcov(tableA10_model2)[10,10]
Cov13 <- vcov(tableA10_model2)[10,2]

american_score <- 0:7

marg.effect <- beta1 + beta3*american_score

marg.effect.var <- V1 + american_score^2*V3 + 2*american_score*Cov13

marg.effect.se <- sqrt(marg.effect.var)

marg.effect.lb <- marg.effect - 1.96*marg.effect.se

marg.effect.ub <- marg.effect + 1.96*marg.effect.se

me.data <- data.frame(american_score,
                      marg.effect,
                      marg.effect.var,
                      marg.effect.se,
                      marg.effect.lb,
                      marg.effect.ub)

figure_A2_2004 <- ggplot(me.data, aes(x=american_score, y=marg.effect)) + 
  geom_line(size=0.75) + 
  geom_hline(yintercept=0, lty=2) + 
  geom_ribbon(aes(ymin=marg.effect.lb, ymax=marg.effect.ub), alpha = 0.25) +
  xlab(expression(AmericanScore[i])) + 
  scale_x_continuous(breaks=seq(0,7, by=1)) + 
  ylab(Marginal ~ Effect ~ of ~ ln(CumulCasualties[jt])) + 
  ggtitle("2004") + 
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5))

rm(beta1,
   beta3,
   V1,
   V3,
   Cov13,
   american_score,
   marg.effect,
   marg.effect.var,
   marg.effect.se,
   marg.effect.lb,
   marg.effect.ub,
   me.data)

## 2005

beta1 <- coef(tableA10_model3)[2]
beta3 <- coef(tableA10_model3)[10]

V1 <- vcov(tableA10_model3)[2,2]
V3 <- vcov(tableA10_model3)[10,10]
Cov13 <- vcov(tableA10_model3)[10,2]

american_score <- 0:7

marg.effect <- beta1 + beta3*american_score

marg.effect.var <- V1 + american_score^2*V3 + 2*american_score*Cov13

marg.effect.se <- sqrt(marg.effect.var)

marg.effect.lb <- marg.effect - 1.96*marg.effect.se

marg.effect.ub <- marg.effect + 1.96*marg.effect.se

me.data <- data.frame(american_score,
                      marg.effect,
                      marg.effect.var,
                      marg.effect.se,
                      marg.effect.lb,
                      marg.effect.ub)

figure_A2_2005 <- ggplot(me.data, aes(x=american_score, y=marg.effect)) + 
  geom_line(size=0.75) + 
  geom_hline(yintercept=0, lty=2) + 
  geom_ribbon(aes(ymin=marg.effect.lb, ymax=marg.effect.ub), alpha = 0.25) +
  xlab(expression(AmericanScore[i])) + 
  scale_x_continuous(breaks=seq(0,7, by=1)) + 
  ylab(Marginal ~ Effect ~ of ~ ln(CumulCasualties[jt])) + 
  ggtitle("2005") + 
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5))

rm(beta1,
   beta3,
   V1,
   V3,
   Cov13,
   american_score,
   marg.effect,
   marg.effect.var,
   marg.effect.se,
   marg.effect.lb,
   marg.effect.ub,
   me.data)

## 2006

beta1 <- coef(tableA10_model4)[2]
beta3 <- coef(tableA10_model4)[10]

V1 <- vcov(tableA10_model4)[2,2]
V3 <- vcov(tableA10_model4)[10,10]
Cov13 <- vcov(tableA10_model4)[10,2]

american_score <- 0:7

marg.effect <- beta1 + beta3*american_score

marg.effect.var <- V1 + american_score^2*V3 + 2*american_score*Cov13

marg.effect.se <- sqrt(marg.effect.var)

marg.effect.lb <- marg.effect - 1.96*marg.effect.se

marg.effect.ub <- marg.effect + 1.96*marg.effect.se

me.data <- data.frame(american_score,
                      marg.effect,
                      marg.effect.var,
                      marg.effect.se,
                      marg.effect.lb,
                      marg.effect.ub)

figure_A2_2006 <- ggplot(me.data, aes(x=american_score, y=marg.effect)) + 
  geom_line(size=0.75) + 
  geom_hline(yintercept=0, lty=2) + 
  geom_ribbon(aes(ymin=marg.effect.lb, ymax=marg.effect.ub), alpha = 0.25) +
  xlab(expression(AmericanScore[i])) + 
  scale_x_continuous(breaks=seq(0,7, by=1)) + 
  ylab(Marginal ~ Effect ~ of ~ ln(CumulCasualties[jt])) + 
  ggtitle("2006") + 
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5))

rm(beta1,
   beta3,
   V1,
   V3,
   Cov13,
   american_score,
   marg.effect,
   marg.effect.var,
   marg.effect.se,
   marg.effect.lb,
   marg.effect.ub,
   me.data)


######################################################################################
## Appendix Table A.11: Cumulative Casualties and American Brand Share, 2003-2006 - ##
## County Fixed Effects                                                             ##
######################################################################################

## Model (1)
tableA11_model1 <- felm(dmshare ~ 
                          log_cum_iraq_cas*am4 + 
                          log_cum_iraq_nat_cas*am4 +
                          zhi*am4 + 
                          enlist*am4 + 
                          dprice + 
                          dnsku | 
                          fips | 
                          0 | 
                          0,
                        data=data_03)

## Model (2)
tableA11_model2 <- felm(dmshare ~ 
                          log_cum_iraq_cas*am4 + 
                          log_cum_iraq_nat_cas*am4 +
                          zhi*am4 + 
                          enlist*am4 + 
                          dprice + 
                          dnsku | 
                          fips | 
                          0 | 
                          0,
                        data=data_04)

## Model (3)
tableA11_model3 <- felm(dmshare ~ 
                          log_cum_iraq_cas*am4 + 
                          log_cum_iraq_nat_cas*am4 +
                          zhi*am4 + 
                          enlist*am4 + 
                          dprice + 
                          dnsku | 
                          fips | 
                          0 | 
                          0,
                        data=data_05)

## Model (4)
tableA11_model4 <- felm(dmshare ~ 
                          log_cum_iraq_cas*am4 + 
                          log_cum_iraq_nat_cas*am4 +
                          zhi*am4 + 
                          enlist*am4 + 
                          dprice + 
                          dnsku | 
                          fips | 
                          0 | 
                          0,
                        data=data_06)


######################################################################################
## Appendix Table A.12: Cumulative Casualties and American Brand Share, 2003-2006 - ## 
## Controlling for Bush Vote Share                                                  ##
######################################################################################

## Model (1)
tableA12_model1 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        bush*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03)

## Model (2)
tableA12_model2 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        bush*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04)

## Model (3)
tableA12_model3 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        bush*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05)

## Model (4)
tableA12_model4 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        bush*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06)


######################################################################################
## Appendix Table A.13: Cumulative Casualties and American Brand Share, 2003-2006 - ##
## Including Afghanistan Casualties                                                 ##
######################################################################################

## Model (1)
tableA13_model1 <- lm(dmshare ~ 
                        log_cum_total_cas*am4 + 
                        log_cum_total_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03)

## Model (2)
tableA13_model2 <- lm(dmshare ~ 
                        log_cum_total_cas*am4 + 
                        log_cum_total_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04)

## Model (3)
tableA13_model3 <- lm(dmshare ~ 
                        log_cum_total_cas*am4 + 
                        log_cum_total_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05)

## Model (4)
tableA13_model4 <- lm(dmshare ~ 
                        log_cum_total_cas*am4 + 
                        log_cum_total_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06)


######################################################################################
## Appendix Table A.14: Cumulative Casualties and American Brand Share, 2003-2006 - ##
## Store-Clustered Standard Errors                                                  ##
######################################################################################

## Model (1)
tableA14_model1 <- felm(dmshare ~ 
                          log_cum_iraq_cas*am4 + 
                          log_cum_iraq_nat_cas*am4 +
                          zhi*am4 + 
                          enlist*am4 + 
                          pop + 
                          dprice + 
                          dnsku | 
                          0 | 
                          0 | 
                          store,
                        data=data_03)

## Model (2)
tableA14_model2 <- felm(dmshare ~ 
                          log_cum_iraq_cas*am4 + 
                          log_cum_iraq_nat_cas*am4 +
                          zhi*am4 + 
                          enlist*am4 + 
                          pop + 
                          dprice + 
                          dnsku | 
                          0 | 
                          0 | 
                          store,
                        data=data_04)

## Model (3)
tableA14_model3 <- felm(dmshare ~ 
                          log_cum_iraq_cas*am4 + 
                          log_cum_iraq_nat_cas*am4 +
                          zhi*am4 + 
                          enlist*am4 + 
                          pop + 
                          dprice + 
                          dnsku | 
                          0 | 
                          0 | 
                          store,
                        data=data_05)

## Model (4)
tableA14_model4 <- felm(dmshare ~ 
                          log_cum_iraq_cas*am4 + 
                          log_cum_iraq_nat_cas*am4 +
                          zhi*am4 + 
                          enlist*am4 + 
                          pop + 
                          dprice + 
                          dnsku | 
                          0 | 
                          0 | 
                          store,
                        data=data_06)


######################################################################################
## Appendix Table A.15: Cumulative Casualties and American Brand Share, 2003-2006 - ##
## Omitting Casualty Outliers                                                       ##
######################################################################################

## Model (1)
tableA15_model1 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku, 
                      data=filter(data_03,
                                  log_cum_iraq_cas < (mean(log_cum_iraq_cas, na.rm=TRUE) + 2*sd(log_cum_iraq_cas, na.rm=TRUE)) &
                                    log_cum_iraq_cas > (mean(log_cum_iraq_cas, na.rm=TRUE) - 2*sd(log_cum_iraq_cas, na.rm=TRUE))))

## Model (2)
tableA15_model2 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku, 
                      data=filter(data_04,
                                  log_cum_iraq_cas < (mean(log_cum_iraq_cas, na.rm=TRUE) + 2*sd(log_cum_iraq_cas, na.rm=TRUE)) &
                                    log_cum_iraq_cas > (mean(log_cum_iraq_cas, na.rm=TRUE) - 2*sd(log_cum_iraq_cas, na.rm=TRUE))))

## Model (3)
tableA15_model3 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku, 
                      data=filter(data_05,
                                  log_cum_iraq_cas < (mean(log_cum_iraq_cas, na.rm=TRUE) + 2*sd(log_cum_iraq_cas, na.rm=TRUE)) &
                                    log_cum_iraq_cas > (mean(log_cum_iraq_cas, na.rm=TRUE) - 2*sd(log_cum_iraq_cas, na.rm=TRUE))))

## Model (4)
tableA15_model4 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku, 
                      data=filter(data_06,
                                  log_cum_iraq_cas < (mean(log_cum_iraq_cas, na.rm=TRUE) + 2*sd(log_cum_iraq_cas, na.rm=TRUE)) &
                                    log_cum_iraq_cas > (mean(log_cum_iraq_cas, na.rm=TRUE) - 2*sd(log_cum_iraq_cas, na.rm=TRUE))))


###########################################################################
## Appendix Table A.16: Cumulative Casualties Weighted by Population and ##
## American Brand Share, 2003-2006                                       ##
###########################################################################

## Model (1)
tableA16_model1 <- lm(dmshare ~ 
                        cum_iraq_cas_pop*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        dprice + 
                        dnsku,
                      data=data_03)

## Model (2)
tableA16_model2 <- lm(dmshare ~ 
                        cum_iraq_cas_pop*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        dprice + 
                        dnsku,
                      data=data_04)

## Model (3)
tableA16_model3 <- lm(dmshare ~ 
                        cum_iraq_cas_pop*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        dprice + 
                        dnsku,
                      data=data_05)

## Model (4)
tableA16_model4 <- lm(dmshare ~ 
                        cum_iraq_cas_pop*am4 + 
                        log_cum_iraq_nat_cas*am4 +
                        zhi*am4 + 
                        enlist*am4 + 
                        dprice + 
                        dnsku,
                      data=data_06)


######################################################################################
## Appendix Table A.17: Cumulative Casualties and American Brand Share, 2003-2006 - ##
## Using 2002 as Baseline Year                                                      ##
######################################################################################

## Model (1)
tableA17_model1 <- lm(dmshare_2002 ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice_2002 + 
                        dnsku_2002,
                      data=data_03)

## Model (2)
tableA17_model2 <- lm(dmshare_2002 ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice_2002 + 
                        dnsku_2002,
                      data=data_04)

## Model (3)
tableA17_model3 <- lm(dmshare_2002 ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice_2002 + 
                        dnsku_2002,
                      data=data_05)

## Model (4)
tableA17_model4 <- lm(dmshare_2002 ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice_2002 + 
                        dnsku_2002,
                      data=data_06)


###################################################################################
## Appendix Table A.18: Weekly Casualties and American Brand Share, 2003-2006 -  ##
## Dichotomized American Score                                                   ##
###################################################################################

## The following commands create new versions of the analysis datasets that
## dichotomize American Score.

data_03_dich <- filter(data_03, am4<=1 | am4>=6)

data_03_dich$am4 <- if_else(data_03_dich$am4<=1, 0, 1)

data_04_dich <- filter(data_04, am4<=1 | am4>=6)

data_04_dich$am4 <- if_else(data_04_dich$am4<=1, 0, 1)

data_05_dich <- filter(data_05, am4<=1 | am4>=6)

data_05_dich$am4 <- if_else(data_05_dich$am4<=1, 0, 1)

data_06_dich <- filter(data_06, am4<=1 | am4>=6)

data_06_dich$am4 <- if_else(data_06_dich$am4<=1, 0, 1)

## Model (1)
tableA18_model1 <- lm(dmshare ~ 
                        casul_ind*am4 + 
                        iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03_dich)

## Model (2)
tableA18_model2 <- lm(dmshare ~ 
                        casul_ind*am4 + 
                        iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04_dich)

## Model (3)
tableA18_model3 <- lm(dmshare ~ 
                        casul_ind*am4 + 
                        iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05_dich)

## Model (4)
tableA18_model4 <- lm(dmshare ~ 
                        casul_ind*am4 + 
                        iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06_dich)


######################################################################################
## Appendix Table A.19: Cumulative Casualties and American Brand Share, 2003-2006 - ##
## Dichotomized American Score                                                      ##
######################################################################################

## Model (1)
tableA19_model1 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03_dich)

## Model (2)
tableA19_model2 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04_dich)

## Model (3)
tableA19_model3 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05_dich)

## Model (4)
tableA19_model4 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4 + 
                        log_cum_iraq_nat_cas*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06_dich)

## Remove dichotomized datasets.
rm(data_03_dich,
   data_04_dich,
   data_05_dich,
   data_06_dich)

gc()


#####################################################################################
## Appendix Table A.20: Baseline Demographic Propensity for American Brands - 2001 ##
#####################################################################################

## Note: this model uses demographic data that is subject to a data
## use agreement. Please see the Readme for additional information.

## Model (1)
tableA20_model1 <- felm(mshare01 ~ 
                          native_percent:amerscore + 
                          black_percent:amerscore +
                          whitecollar_percent:amerscore + 
                          bush:amerscore +
                          armedforces_percent:amerscore + 
                          mprice01 + 
                          mnumsku01 + 
                          amerscore |
                          category + store + week | 
                          0 | 
                          0,
                        data=filter(data_demo, week<=36 & pop < (mean(pop) + 2*sd(pop)) & pop > (mean(pop) - 2*sd(pop))))


######################################################################
## Appendix Table A.21: Casualty Exposure and Political Advertising ##
######################################################################

## Note: run the script "wesleyan_media_project_script.R" prior to
## estimating the following models. These models use data from the 
## Wesleyan Media Project that is subject to a data use agreement.
## Please see the Readme for additional information.

## Model (1)
tableA21_model1 <- lm(dmshare ~ 
                        log_cum_iraq_cas*share_iraq*am4 + 
                        time_total*am4 + 
                        bush*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        dprice + 
                        dnsku,
                      data=data_06)

## Model (2)
tableA21_model2 <- lm(dmshare ~ 
                        log_cum_iraq_cas*share_iraq_dem*am4 +
                        time_total*am4 + 
                        bush*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        dprice + 
                        dnsku,
                      data=data_06)

## Model (3)
tableA21_model3 <- lm(dmshare ~ 
                        log_cum_iraq_cas*share_iraq_rep*am4 +
                        time_total*am4 + 
                        bush*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        dprice + 
                        dnsku,
                      data=data_06)

## Model (4)
tableA21_model4 <- lm(dmshare ~ 
                        log_cum_iraq_cas*share_iraq_dem*am4 +
                        log_cum_iraq_cas*share_iraq_rep*am4 +
                        time_total*am4 + 
                        bush*am4 + 
                        zhi*am4 + 
                        enlist*am4 + 
                        dprice + 
                        dnsku,
                      data=data_06)


####################################################################################################
## Appendix Table A.22: Cumulative Casualties and Coalition of the Willing Brand Share, 2003-2006 ##
####################################################################################################

## The code that follows assumes that the user has created a set
## of annual versions of the data for years 2003-2006, with the
## names data_03_coalition, data_04_coalition, data_05_coalition,
## and data_06_coalition.

## Model (1)
tableA22_model1 <- lm(dmshare ~ 
                        log_cum_iraq_cas*coalition_score + 
                        log_cum_iraq_nat_cas*coalition_score +
                        zhi*coalition_score + 
                        enlist*coalition_score + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03_coalition)

## Model (2)
tableA22_model2 <- lm(dmshare ~ 
                        log_cum_iraq_cas*coalition_score + 
                        log_cum_iraq_nat_cas*coalition_score +
                        zhi*coalition_score + 
                        enlist*coalition_score + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04_coalition)

## Model (3)
tableA22_model3 <- lm(dmshare ~ 
                        log_cum_iraq_cas*coalition_score + 
                        log_cum_iraq_nat_cas*coalition_score +
                        zhi*coalition_score + 
                        enlist*coalition_score + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05_coalition)

## Model (4)
tableA22_model4 <- lm(dmshare ~ 
                        log_cum_iraq_cas*coalition_score + 
                        log_cum_iraq_nat_cas*coalition_score +
                        zhi*coalition_score + 
                        enlist*coalition_score + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06_coalition)


##########################################################################################
## Appendix Table A.23: Cumulative Casualties and France/Germany Brand Share, 2003-2006 ##
##########################################################################################

## The code that follows assumes that the user has created a set
## of annual versions of the data for years 2003-2006, with the
## names data_03_fg, data_04_fg, data_05_fg, and data_06_fg.

## Model (1)
tableA23_model1 <- lm(dmshare ~ 
                        log_cum_iraq_cas*france_germany_score + 
                        log_cum_iraq_nat_cas*france_germany_score +
                        zhi*france_germany_score + 
                        enlist*france_germany_score + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03_fg)

## Model (2)
tableA23_model2 <- lm(dmshare ~ 
                        log_cum_iraq_cas*france_germany_score + 
                        log_cum_iraq_nat_cas*france_germany_score +
                        zhi*france_germany_score + 
                        enlist*france_germany_score + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04_fg)

## Model (3)
tableA23_model3 <- lm(dmshare ~ 
                        log_cum_iraq_cas*france_germany_score + 
                        log_cum_iraq_nat_cas*france_germany_score +
                        zhi*france_germany_score + 
                        enlist*france_germany_score + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05_fg)

## Model (4)
tableA23_model4 <- lm(dmshare ~ 
                        log_cum_iraq_cas*france_germany_score + 
                        log_cum_iraq_nat_cas*france_germany_score +
                        zhi*france_germany_score + 
                        enlist*france_germany_score + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06_fg)


###############################################################################
## Appendix Table A.24: Effect Heterogeneity in Food vs. Non-Food Products - ##
## Weekly Casualties                                                         ##
###############################################################################

## Model (1)
tableA24_model1 <- lm(dmshare ~ 
                        casul_ind*am4*food + 
                        iraq_nat_cas*am4*food + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03)

## Model (2)
tableA24_model2 <- lm(dmshare ~ 
                        casul_ind*am4*food + 
                        iraq_nat_cas*am4*food + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04)

## Model (3)
tableA24_model3 <- lm(dmshare ~ 
                        casul_ind*am4*food + 
                        iraq_nat_cas*am4*food + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05)

## Model (4)
tableA24_model4 <- lm(dmshare ~ 
                        casul_ind*am4*food + 
                        iraq_nat_cas*am4*food + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06)


###############################################################################
## Appendix Table A.25: Effect Heterogeneity in Food vs. Non-Food Products - ##
## Cumulative Casualties                                                     ##
###############################################################################

## Model (1)
tableA25_model1 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4*food + 
                        log_cum_iraq_nat_cas*am4*food + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03)

## Model (2)
tableA25_model2 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4*food + 
                        log_cum_iraq_nat_cas*am4*food + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04)

## Model (3)
tableA25_model3 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4*food + 
                        log_cum_iraq_nat_cas*am4*food + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05)


## Model (4)
tableA25_model4 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4*food + 
                        log_cum_iraq_nat_cas*am4*food + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06)


#####################################################################################
## Appendix Table A.26: Effect Heterogeneity in Hedonic vs. Non-Hedonic Products - ##
## Weekly Casualties                                                               ##
#####################################################################################

## Model (1)
tableA26_model1 <- lm(dmshare ~ 
                        casul_ind*am4*hedonic + 
                        iraq_nat_cas*am4*hedonic + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03)

## Model (2)
tableA26_model2 <- lm(dmshare ~ 
                        casul_ind*am4*hedonic + 
                        iraq_nat_cas*am4*hedonic + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04)

## Model (3)
tableA26_model3 <- lm(dmshare ~ 
                        casul_ind*am4*hedonic + 
                        iraq_nat_cas*am4*hedonic + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05)

## Model (4)
tableA26_model4 <- lm(dmshare ~ 
                        casul_ind*am4*hedonic + 
                        iraq_nat_cas*am4*hedonic + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06)


#####################################################################################
## Appendix Table A.27: Effect Heterogeneity in Hedonic vs. Non-Hedonic Products - ##
## Cumulative Casualties                                                           ##
#####################################################################################

## Model (1)
tableA27_model1 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4*hedonic + 
                        log_cum_iraq_nat_cas*am4*hedonic + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_03)

## Model (2)
tableA27_model2 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4*hedonic + 
                        log_cum_iraq_nat_cas*am4*hedonic + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_04)

## Model (3)
tableA27_model3 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4*hedonic + 
                        log_cum_iraq_nat_cas*am4*hedonic + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_05)

## Model (4)
tableA27_model4 <- lm(dmshare ~ 
                        log_cum_iraq_cas*am4*hedonic + 
                        log_cum_iraq_nat_cas*am4*hedonic + 
                        zhi*am4 + 
                        enlist*am4 + 
                        pop + 
                        dprice + 
                        dnsku,
                      data=data_06)



